package com.ymatou.iapi.liveseller.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.SuspendLiveProductBean;
import com.ymatou.iapi.liveseller.service.SuspendLiveProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.CounterCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*暂停销售商品
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SuspendLiveProduct{
	private static SuspendLiveProductBean suspendliveproductBean;
	private static SuspendLiveProductCall suspendliveproductCall;
	private static LiveRoomWapper liveRoomWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("暂停销售商品");
	}

	@Before
	public void caseUp() {
		suspendliveproductBean=new SuspendLiveProductBean();
		suspendliveproductCall=new SuspendLiveProductCall();
		liveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(suspendliveproductCall.getOpurl());
		liveRoomWapper=null;
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SuspendLiveProduct_001() {
		Logger.start(true,"status0未开始直播暂停销售商品成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("200", suspendliveproductCall.getString("Code"), "验证Code");
			List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(createlive.getId(), pid);
			Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
			Logger.verifyEquals(0, listm.get(0).get("Status"), "验证Status暂停");
			Logger.debug(listm);
			
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(0, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SuspendLiveProduct_002() {
		Logger.start(true,"不输入liveid失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("400", suspendliveproductCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("参数错误", suspendliveproductCall.getString("Msg"), "验证Msg");
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(1, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SuspendLiveProduct_003() {
		Logger.start(true,"不输入ProductId失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			suspendliveproductBean.setLiveId(createlive.getId());
//			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("200", suspendliveproductCall.getString("Code"), "验证Code");
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			//校验商品不会修改在售状态
			Logger.verifyEquals(1, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SuspendLiveProduct_004() {
		Logger.start(true,"liveid和ProductId不匹配不操作");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			suspendliveproductBean.setLiveId(createlive.getId()+1);
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("201", suspendliveproductCall.getString("Code"), "验证Code");
			
			Logger.comment("不匹配不修改");
			List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(createlive.getId(), pid);
			Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
			Logger.verifyEquals(1, listm.get(0).get("Status"), "验证Status暂停");
			Logger.debug(listm);
			
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(1, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SuspendLiveProduct_005() {
		Logger.start(true,"ProductId不存在不操作");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid+1);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("200", suspendliveproductCall.getString("Code"), "验证Code");
			
			Logger.comment("不匹配不修改");
			List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(createlive.getId(), pid);
			Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
			Logger.verifyEquals(1, listm.get(0).get("Status"), "验证Status暂停");
			Logger.debug(listm);
			
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(1, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SuspendLiveProduct_009() {
		Logger.start(true,"status7直播推流结束暂停销售商品失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 7);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("201", suspendliveproductCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", suspendliveproductCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SuspendLiveProduct_010() {
		Logger.start(true,"status2推流直播暂停销售商品成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("200", suspendliveproductCall.getString("Code"), "验证Code");
			List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(createlive.getId(), pid);
			Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
			Logger.verifyEquals(0, listm.get(0).get("Status"), "验证Status暂停");
			Logger.debug(listm);
			
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(0, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SuspendLiveProduct_011() {
		Logger.start(true,"status3断流直播暂停销售商品成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 3);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("200", suspendliveproductCall.getString("Code"), "验证Code");
			List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(createlive.getId(), pid);
			Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
			Logger.verifyEquals(0, listm.get(0).get("Status"), "验证Status暂停");
			Logger.debug(listm);
			
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(0, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SuspendLiveProduct_012() {
		Logger.start(true,"暂停销售商品后开始销售再暂停销售成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SuspendLiveProduct(createlive.getId(), pid);
			LiveRoomCallService.ResumeLiveProduct(createlive.getId(), pid);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("200", suspendliveproductCall.getString("Code"), "验证Code");
			List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(createlive.getId(), pid);
			Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
			Logger.verifyEquals(0, listm.get(0).get("Status"), "验证Status暂停");
			Logger.debug(listm);
			
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(0, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SuspendLiveProduct_013() {
		Logger.start(true,"status8直播推流结束暂停销售商品失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(),8);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("201", suspendliveproductCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", suspendliveproductCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SuspendLiveProduct_014() {
		Logger.start(true,"status9直播推流结束暂停销售商品失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(),9);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("201", suspendliveproductCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", suspendliveproductCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SuspendLiveProduct_015() {
		Logger.start(true,"status10直播推流结束暂停销售商品失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(),10);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			suspendliveproductCall.callService();
			Logger.verifyEquals("201", suspendliveproductCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", suspendliveproductCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SuspendLiveProduct_016() {
		Logger.start(true,"status0未开始直播暂停销售商品成功、计数器+1");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			suspendliveproductBean.setLiveId(createlive.getId());
			suspendliveproductBean.setProductId(pid);
			suspendliveproductCall.setData(suspendliveproductBean);
			
			Integer counter = CounterCallService.getSingleValueByLiveId(createlive.getId());
			suspendliveproductCall.callService();	
			Integer counter1 = CounterCallService.getSingleValueByLiveId(createlive.getId());
			Logger.verifyEquals(counter+1, counter1, "添加商品之后，计数器+1");
			
			Logger.verifyEquals("200", suspendliveproductCall.getString("Code"), "验证Code");
			List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(createlive.getId(), pid);
			Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
			Logger.verifyEquals(0, listm.get(0).get("Status"), "验证Status暂停");
			Logger.debug(listm);
			
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(0, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(1, liveroom.getLiveProductNum(), "验证LiveProductNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}